<?  /*
     * // File:restore.php
     * // Purpose:restores a backup
     * // Author:Peter Drake <peterdrake@241computers.com>
     * //        Ed Gray <edgray@vxcomputers.com>
     * */

// Perform restore
for($i = 0; $i < sizeOf($restoreFiles); $i++) {
    // filelocation is the full path to this backup
    $filelocation = $restoreFiles[$i];
    // Array containing full file path
    $curArray = explode("/", $filelocation);

    $domainname = $curArray[2];
    $filename = $curArray[4];

    webcp_log(2,0,'restore.php',"Restore: Started for ".$domainname,0,$echo);

    // Generate tmpdirectory name from filename
    $tmpdirectory = str_replace('.tar.gz', '', $filename);
    // Create a tmpdirectory for extraction of backup archive
    mkdir('/tmp/'.$tmpdirectory, 0744);
    chdir('/tmp/'.$tmpdirectory);
    // Copy backup file to tmpdirectory
    copy($filelocation, '/tmp/'.$tmpdirectory.'/'.$filename);
    // Extract backup archive in tmpdirectory
    exec('tar -xzf /tmp/'.$tmpdirectory.'/'.$filename);

    $filesto = $cfg['webdir']."/".$domainname;

    rm($filesto.'/_logs');
    rm($filesto.'/www');
    exec('mv -f /tmp/'.$tmpdirectory.'/_logs '.$filesto);
    exec('mv -f /tmp/'.$tmpdirectory.'/www '.$filesto);
    
    webcp_log(2,0,'restore.php',"Restore: Completed in ".$filesto,0,$echo);

    webcp_log(2,0,'restore.php',"Restore: Cleaning up",0,$echo);
    rm('/tmp/'.$tmpdirectory);
}
?>
